/**
 * related to detail.ui
 * 
 * @Author : chenglm
 * @Timestamp : 2016-12-19
 */
var page = sm("do_Page");
var app = sm("do_App");
var nf = sm("do_Notification");
var do_External = sm("do_External");
var global = deviceone.sm("do_Global");
var imHelper = require("helper/im");
var bizzType = require("helper/bizzType");
var pubUrl = require("url/pub");
var qqHttp = require("helper/http");
var mallUrl = require("url/mall");
var hashdata = mm("do_HashData");
var linearLayout_main = ui("do_LinearLayout_main");
var imageView_logo = ui("imageView_logo");
var label_shopName = ui("label_shopName");
var label_shopResume = ui("label_shopResume");
var aLayout_sellePhone = ui("aLayout_sellePhone");
var label_busTime = ui("label_busTime");
var categoryName = ui("categoryName");
var aLayout_concern = ui("aLayout_concern");
/* 头部 */
var headerAout = ui("do_ALayout_header");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var header = ui("header");
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
var labelTitle = ui(addheader+".labelTitle");
labelTitle.text='店铺信息';
headerLeft.on("touch", function() {
	app.closePage({"fromPage":"shopDetail","hasCollect":shop.hasCollect});
});
var shop = null;
//andriod返回键
page.on("back", function() {
    app.closePage({"fromPage":"shopDetail","hasCollect":shop.hasCollect});
});
page.on("loaded", function(){
	var jsonData = page.getData();
	init(jsonData.shopId);
});
function init(shopId){
	qqHttp.post(mallUrl.url.shop.detailByShopId, {id:shopId}, function(data) {
		shop = data.mallShop;
		imageView_logo.source = shop.fullLogo;
		label_shopName.text = shop.name;
		label_shopResume.text = shop.resume;
		label_busTime.text = shop.busStart + "~" + shop.busEnd;
		categoryName.text = shop.categoryName;
		ui("shopPhone").text = shop.phone;
		ui("shopAddress").text = shop.address;
		ui("sendDeliveryType").text = shop.sendDeliveryTypeStr;
		ui("label_shopUserNick").text = shop.userNick;
		ui("label_shopUserNick").tag = shop.creatorId;
		var auditStatus = ui("auditStatus");
		if (shop.auditStatus == 1) {
			auditStatus.text = "待审核";
		} else if (shop.auditStatus == 2) {
			auditStatus.text = "已通过";
			auditStatus.fontColor = "1eaa39FF";
		} else {
			auditStatus.text = "不通过";
			auditStatus.fontColor = "ff5305FF";
		}
		if (shop.style==2) {
			ui("linearLayout_licensePic").visible = true;
			ui("licensePic").text = "已上传";
		}
		if (shop.hasCollect) {
			aLayout_concern.border = 'fe7e0aFF,1,4';
			ui("do_ImageView_6").source = 'source://image/community/star_on.png';
			ui("do_Label_17").fontColor = 'FE7E0AFF';
		} else {
			aLayout_concern.border = '949EAAFF,1,4';
			ui("do_ImageView_6").source = 'source://image/community/star.png';
			ui("do_Label_17").fontColor = '949EAAFF';
		}
	});
};

aLayout_sellePhone.on("touch", function(data){
	do_External.openDial(ui("shopPhone").text);
});
aLayout_concern.on("touch", function(data){
	var addParams = {
		bizzId : shop.id,
		bizzType : bizzType.Level2.QSHOP_SHOP
	};
	if (shop.hasCollect) {
		qqHttp.post(pubUrl.url.concern.doCancle, addParams, function(data) {
			aLayout_concern.border = '949EAAFF,1,4';
			ui("do_ImageView_6").source = 'source://image/community/star.png';
			ui("do_Label_17").fontColor = '949EAAFF';
			shop.hasCollect = false;
		});
	} else {
		qqHttp.post(pubUrl.url.concern.doAdd, addParams, function(data) {
			aLayout_concern.border = 'fe7e0aFF,1,4';
			ui("do_ImageView_6").source = 'source://image/community/star_on.png';
			ui("do_Label_17").fontColor = 'FE7E0AFF';
			shop.hasCollect = true;
		});
	}
});
//与店主聊天
ui("do_ALayout_chatIM").on("touch",'' ,300,function(data, e) {
	var shopOwnerId = ui("label_shopUserNick").tag;
	imHelper.toChat(shopOwnerId);
});